package com.iuschool.demo.resource;

import org.springframework.core.io.FileSystemResource;

import java.io.*;

/**
 * @author max
 * @version 1.0.0
 * @ClassName ResourceDemo.java
 * @Description 演示通过 FileSystemResource 改写资源文件
 * @createTime 2020年09月18日 14:27:00
 */
public class ResourceDemo {
	public static void main(String[] args) throws IOException {
		FileSystemResource fileSystemResource = new FileSystemResource(
				"/Users/max/working/java-project/open-source/spring-framework-5.2.8.RELEASE/springdemo/src/main/java/com/iuschool/demo/resource/resource.txt"
		);
		File file = fileSystemResource.getFile();
		System.out.println("文件长度: " + file.length());
		OutputStream os = fileSystemResource.getOutputStream();
		BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os));
		bufferedWriter.write("replace");
		bufferedWriter.flush();
		os.close();
		bufferedWriter.close();
	}
}
